﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DALEF;


namespace DALEF
{
    public  class ModelTranslator
    {
        public static List<Model.Department> DepartmentEFtoDepartment(List<Department> DepartmentInstance)// translator Department Entity Framework to Department 
        {
            List<Model.Department> dep = new List<Model.Department>();

            foreach (var a in DepartmentInstance)
            {
                Model.Department b = new Model.Department()
                {
                    DepartmentId = a.DepartmentId,
                    DepartmentName = a.DepartmentName,
                    Manager = a.Manager,
                    Phone = a.Phone,
                    Remark = a.Remark 
                };

                dep.Add(b);

            }
            return dep;
        }

        public static List<Department> DepartmenttoDepartmentEF(List<Model.Department> DepartmentInstance) 
        {
            List<Department> dep = new List<Department>();
            foreach (var a in DepartmentInstance)
            {
                Department b = new Department() 
                {
                    DepartmentId = a.DepartmentId == 0 ? 0 : a.DepartmentId,
                    DepartmentName = a.DepartmentName == null ? "" : a.DepartmentName,
                    Manager = a.Manager == null ? "" : a.Manager,
                    Phone = a.Phone == null ? "" : a.Phone,
                    Remark = a.Remark == null ? "" : a.Remark
                };

                dep.Add(b);
            }
            return dep;
        }

        public static List<Model.Teacher> TeacherEFtoTeacher(List<Teacher> TeacherInstance)//translator teacher entity framework to teacher
        {
            List<Model.Teacher> tea = new List<Model.Teacher>();

            foreach (var a in TeacherInstance)
            {
                Model.Teacher b = new Model.Teacher()
                {
                    TeacherId = a.TeacherId,
                    TeacherName = a.TeacherName,
                    TeacherGender = a.TeacherGender,
                    DepartMent = new Model.Department()
                    {
                        DepartmentId = a.DepartmentId,
                        DepartmentName = a.Department.DepartmentName,//嵌套定义模版带来的好处！！！！！！
                        Manager= a.Department.Manager,
                        Phone = a.Department.Phone,
                        Remark = a.Department.Remark
                    },

                };

                tea.Add(b);
            }

            return tea;
        }

        public static List<Teacher> TeachertoTeacherEF(List<Model.Teacher> TeacherInstance)
        {
            List<Teacher> tea = new List<Teacher>();
           
                foreach (var a in TeacherInstance)
                {
                    Teacher b = new Teacher()
                    {
                        TeacherId = a.TeacherId == 0 ? 0 : a.TeacherId,
                        TeacherName = a.TeacherName == null ? "" : a.TeacherName,
                        TeacherGender = a.TeacherGender ==null ? "" : a.TeacherGender,
                        DepartmentId = a.DepartMent==null? 0 : a.DepartMent.DepartmentId,
                        Department = new Department()
                        {
                            DepartmentId = a.DepartMent==null ? 0 : a.DepartMent.DepartmentId == 0 ? 0 : a.DepartMent.DepartmentId,
                            DepartmentName = a.DepartMent==null ? "" :  a.DepartMent.DepartmentName == null ? "" : a.DepartMent.DepartmentName,
                            Manager = a.DepartMent==null ? "":  a.DepartMent.Manager == null ? "" : a.DepartMent.Manager,
                            Phone = a.DepartMent==null ? "":  a.DepartMent.Phone == null ? "" :a.DepartMent.Phone  ,
                            Remark = a.DepartMent ==null ? "":  a.DepartMent.Remark == null ? "": a.DepartMent.Remark
                        },

                    };

                    tea.Add(b);
                }
                return tea;
           
        }


      
    }
 }
